package com.hngates.architecture.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hngates.common.annotation.Log;
import com.hngates.common.enums.BusinessType;
import com.hngates.architecture.domain.ArcLabourCompany;
import com.hngates.architecture.service.IArcLabourCompanyService;
import com.hngates.common.core.controller.BaseController;
import com.hngates.common.core.domain.AjaxResult;
import com.hngates.common.utils.poi.ExcelUtil;
import com.hngates.common.core.page.TableDataInfo;

/**
 * 施工单位Controller
 * 
 * @author jwhe
 * @date 2022-07-04
 */
@Controller
@RequestMapping("/architecture/labourCompany")
public class ArcLabourCompanyController extends BaseController
{
    private String prefix = "architecture/labourCompany";

    @Autowired
    private IArcLabourCompanyService arcLabourCompanyService;

    @RequiresPermissions("architecture:labourCompany:view")
    @GetMapping()
    public String labourCompany()
    {
        return prefix + "/labourCompany";
    }

    /**
     * 查询施工单位列表
     */
    @RequiresPermissions("architecture:labourCompany:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ArcLabourCompany arcLabourCompany)
    {
        startPage();
        List<ArcLabourCompany> list = arcLabourCompanyService.selectArcLabourCompanyList(arcLabourCompany);
        return getDataTable(list);
    }

    /**
     * 导出施工单位列表
     */
    @RequiresPermissions("architecture:labourCompany:export")
    @Log(title = "施工单位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ArcLabourCompany arcLabourCompany)
    {
        List<ArcLabourCompany> list = arcLabourCompanyService.selectArcLabourCompanyList(arcLabourCompany);
        ExcelUtil<ArcLabourCompany> util = new ExcelUtil<ArcLabourCompany>(ArcLabourCompany.class);
        return util.exportExcel(list, "施工单位数据");
    }

    /**
     * 新增施工单位
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存施工单位
     */
    @RequiresPermissions("architecture:labourCompany:add")
    @Log(title = "施工单位", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ArcLabourCompany arcLabourCompany)
    {
        return toAjax(arcLabourCompanyService.insertArcLabourCompany(arcLabourCompany));
    }

    /**
     * 修改施工单位
     */
    @RequiresPermissions("architecture:labourCompany:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ArcLabourCompany arcLabourCompany = arcLabourCompanyService.selectArcLabourCompanyById(id);
        mmap.put("arcLabourCompany", arcLabourCompany);
        return prefix + "/edit";
    }

    /**
     * 修改保存施工单位
     */
    @RequiresPermissions("architecture:labourCompany:edit")
    @Log(title = "施工单位", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ArcLabourCompany arcLabourCompany)
    {
        return toAjax(arcLabourCompanyService.updateArcLabourCompany(arcLabourCompany));
    }

    /**
     * 删除施工单位
     */
    @RequiresPermissions("architecture:labourCompany:remove")
    @Log(title = "施工单位", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(arcLabourCompanyService.deleteArcLabourCompanyByIds(ids));
    }
}
